/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    TreeNode* addOneRow(TreeNode* root, int val, int depth) {
          if(depth==1)
  {
     TreeNode* curr1=new TreeNode (val);
     curr1->left=root;
     return curr1;
  }
  queue<TreeNode*> q;
  q.push(root);
  while(!q.empty())
  {
     depth--;
     if(depth==1)
     {
       while(!q.empty())
       {
         TreeNode* a,*c;
         TreeNode* b=q.front();
         q.pop();
             a=b->left;
             b->left=new TreeNode (val);
             b->left->left=a;
            c=b->right;
            b->right=new TreeNode (val);
            b->right->right=c;
       }
     
     }
     int count=q.size();
     for(int i=0;i<count;i++)
     {
             TreeNode* curr3=q.front();
             q.pop();
             if(curr3->left!=NULL) q.push(curr3->left);
             if(curr3->right!=NULL) q.push(curr3->right);
     }
  }
    return root;
    }
};
